package com.ruoyi.dev.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dev.domain.DevDataset;
import com.ruoyi.dev.service.IDevDatasetService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 数据集Controller
 * 
 * @author yepanpan
 * @date 2024-12-23
 */
@RestController
@RequestMapping("/dev/dataset")
public class DevDatasetController extends BaseController
{
    @Autowired
    private IDevDatasetService devDatasetService;


    /**
     * 查询数据集列表
     */
    @GetMapping("/query")
    public AjaxResult query(DevDataset devDataset)
    {
        return success(devDatasetService.queryDataset(devDataset));
    }


    /**
     * 获取数据集详细信息
     */
    @GetMapping(value = "/info/{code}")
    public AjaxResult getInfo(@PathVariable("code") String code)
    {
        return success(devDatasetService.selectDevDatasetByCode(code));
    }

    /**
     * 查询数据集列表
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:list')")
    @GetMapping("/list")
    public TableDataInfo list(DevDataset devDataset)
    {
        startPage();
        List<DevDataset> list = devDatasetService.selectDevDatasetList(devDataset);
        return getDataTable(list);
    }

    /**
     * 导出数据集列表
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:export')")
    @Log(title = "数据集", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DevDataset devDataset)
    {
        List<DevDataset> list = devDatasetService.selectDevDatasetList(devDataset);
        ExcelUtil<DevDataset> util = new ExcelUtil<DevDataset>(DevDataset.class);
        util.exportExcel(response, list, "数据集数据");
    }

    /**
     * 获取数据集详细信息
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(devDatasetService.selectDevDatasetById(id));
    }

    /**
     * 新增数据集
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:add')")
    @Log(title = "数据集", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DevDataset devDataset)
    {
        return toAjax(devDatasetService.insertDevDataset(devDataset));
    }

    /**
     * 修改数据集
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:edit')")
    @Log(title = "数据集", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DevDataset devDataset)
    {
        return toAjax(devDatasetService.updateDevDataset(devDataset));
    }

    /**
     * 删除数据集
     */
    @PreAuthorize("@ss.hasPermi('dev:dataset:remove')")
    @Log(title = "数据集", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(devDatasetService.deleteDevDatasetByIds(ids));
    }
}
